/*!
 * tykhome - soft.js
 * Author tykhome <yongketian@gmail.com>
 */

/**
 * Soft dependencies.
 */

var securePort = process.env.PORT || 443;

var express = require('express');
var router = express.Router();

var auth = require('../middlewares/auth');
var forceSecure = require('../middlewares/httpsRedirect').forceSecure(securePort);
var soft = require('../controllers/soft');

// Express 4.x 新用法
// 中间件重用
// var bookRouter = express.Router();
// app.use('/books', bookRouter);

// bookRouter.use(parseBook);
// // 下面三个控制器都会经过 parseBook 中间件
// bookRouter.get('/books/:bookId', viewBook);
// bookRouter.get('/books/:bookId/edit', editBook);
// bookRouter.get('/books/:bookId/move', moveBook);

// 搭建 rest-ful 服务
// var bookRouter = express.Router();
// bookRouter
//     .route('/books/:bookId?')
//     .get(function (req, res) {
//         // ...
//     })
//     .put(function (req, res) {
//         // ...
//     })
//     .post(function (req, res) {
//         // ...
//     })
//     .delete(function (req, res) {
//         // ...
//     })

// ===============================
// ========Soft Controller========
// ===============================
router.get('/', soft.list);
router.get('/list', soft.list);
// save
router.get('/create', auth.signinRequired, soft.showCreateForm);
router.post('/create', auth.userRequired, soft.create);
// get
router.get('/:id', soft.view);
// update
router.get('/:id/update', auth.signinRequired, soft.showUpdateForm);
router.post('/:id/update', auth.userRequired, soft.update);
// delete
// app.get('/soft/:id/delete', auth.signinRequired, soft.showDeleteForm);
router.post('/:id/delete', auth.userRequired, soft.delete);
// app.get('/soft/batch/delete', auth.userRequired, soft.deleteInBatch);

module.exports = router;